package com.zzjc.web.controller;

import com.zzjc.web.entity.SwimmingPool;
import com.zzjc.web.service.SwimmingPoolService;
import com.zzjc.web.util.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "泳池管理接口")
@RestController
@RequestMapping("/swimmingPool")
public class SwimmingPoolController {

    @Autowired
    private SwimmingPoolService swimmingPoolService;

    @ApiOperation("添加游泳池信息")
    @PostMapping("/addPool")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "poolName", value = "游泳池名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "length", value = "长度", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "width", value = "宽度", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "rows", value = "行数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "columns", value = "列数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "address", value = "地址", required = false, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "联系电话", required = false, dataType = "String"),
            @ApiImplicitParam(name = "notes", value = "备注", required = false, dataType = "String"),
            @ApiImplicitParam(name = "region", value = "区域", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "waterTemperature", value = "水温", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "roomTemperature", value = "室温", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "ph", value = "PH值", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "turbidity", value = "浊度", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "residualChlorine", value = "余氯", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "poolResidualChlorine", value = "池水余氯", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "peopleNumber", value = "人数", required = false, dataType = "Integer")
    })
    public ApiResponse<?> addPool(
            @RequestParam(value = "poolName", required = true) String poolName,
            @RequestParam(value = "length", required = false) Double length,
            @RequestParam(value = "width", required = false) Double width,
            @RequestParam(value = "rows", required = false) Integer rows,
            @RequestParam(value = "columns", required = false) Integer columns,
            @RequestParam(value = "address", required = false) String address,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "notes", required = false) String notes,
            @RequestParam(value = "region", required = false) Integer region,
            @RequestParam(value = "waterTemperature", required = false) Integer waterTemperature,
            @RequestParam(value = "roomTemperature", required = false) Integer roomTemperature,
            @RequestParam(value = "ph", required = false) Double ph,
            @RequestParam(value = "turbidity", required = false) Integer turbidity,
            @RequestParam(value = "residualChlorine", required = false) Double residualChlorine,
            @RequestParam(value = "poolResidualChlorine", required = false) Double poolResidualChlorine,
            @RequestParam(value = "peopleNumber", required = false) Integer peopleNumber) {
        SwimmingPool pool = new SwimmingPool();
        pool.setPoolName(poolName);
        pool.setLength(length);
        pool.setWidth(width);
        pool.setRows(rows);
        pool.setColumns(columns);
        pool.setAddress(address);
        pool.setPhone(phone);
        pool.setNotes(notes);
        pool.setStatus(1);
        pool.setRegion(region);
        pool.setWaterTemperature(waterTemperature);
        pool.setRoomTemperature(roomTemperature);
        pool.setPh(ph);
        pool.setTurbidity(turbidity);
        pool.setResidualChlorine(residualChlorine);
        pool.setPoolResidualChlorine(poolResidualChlorine);
        pool.setPeopleNumber(peopleNumber);
        return swimmingPoolService.addPool(pool);
    }

    @ApiOperation("更新游泳池信息")
    @PostMapping("/updatePool")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "poolId", value = "游泳池ID", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "poolName", value = "游泳池名称", required = false, dataType = "String"),
            @ApiImplicitParam(name = "length", value = "长度", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "width", value = "宽度", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "rows", value = "行数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "columns", value = "列数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "address", value = "地址", required = false, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "联系电话", required = false, dataType = "String"),
            @ApiImplicitParam(name = "notes", value = "备注", required = false, dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "region", value = "区域", required = false, dataType = "String"),
            @ApiImplicitParam(name = "waterTemperature", value = "水温", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "roomTemperature", value = "室温", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "ph", value = "PH值", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "turbidity", value = "浊度", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "residualChlorine", value = "余氯", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "poolResidualChlorine", value = "池水余氯", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "peopleNumber", value = "人数", required = false, dataType = "Integer")
    })
    public ApiResponse<?> updatePool(SwimmingPool swimmingPool){
//            @RequestParam(value = "poolId", required = true) Integer poolId,
//            @RequestParam(value = "poolName", required = false) String poolName,
//            @RequestParam(value = "length", required = false) Double length,
//            @RequestParam(value = "width", required = false) Double width,
//            @RequestParam(value = "rows", required = false) Integer rows,
//            @RequestParam(value = "columns", required = false) Integer columns,
//            @RequestParam(value = "address", required = false) String address,
//            @RequestParam(value = "phone", required = false) String phone,
//            @RequestParam(value = "notes", required = false) String notes,
//            @RequestParam(value = "region", required = false) Integer region,
//            @RequestParam(value = "waterTemperature", required = false) Integer waterTemperature,
//            @RequestParam(value = "roomTemperature", required = false) Integer roomTemperature,
//            @RequestParam(value = "ph", required = false) Double ph,
//            @RequestParam(value = "turbidity", required = false) Integer turbidity,
//            @RequestParam(value = "residualChlorine", required = false) Double residualChlorine,
//            @RequestParam(value = "poolResidualChlorine", required = false) Double poolResidualChlorine,
//            @RequestParam(value = "peopleNumber", required = false) Integer peopleNumber) {
//        SwimmingPool pool = new SwimmingPool();
//        pool.setPoolId(poolId);
//        pool.setPoolName(poolName);
//        pool.setLength(length);
//        pool.setWidth(width);
//        pool.setRows(rows);
//        pool.setColumns(columns);
//        pool.setAddress(address);
//        pool.setPhone(phone);
//        pool.setNotes(notes);
//        pool.setRegion(region);
//        pool.setWaterTemperature(waterTemperature);
//        pool.setRoomTemperature(roomTemperature);
//        pool.setPh(ph);
//        pool.setTurbidity(turbidity);
//        pool.setResidualChlorine(residualChlorine);
//        pool.setPoolResidualChlorine(poolResidualChlorine);
//        pool.setPeopleNumber(peopleNumber);
        return swimmingPoolService.updatePool(swimmingPool);
    }

    @ApiOperation("删除游泳池")
    @PostMapping("/deletePool")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "poolList", value = "游泳馆id集合", dataType = "String", required = true)
    })
    public ApiResponse deletePool(
            @RequestParam(value = "poolList", required = true) List<Integer> poolList) {
        return swimmingPoolService.deletePool(poolList);
    }



    @ApiOperation("获取游泳池列表")
    @PostMapping("/listPool")
    @ApiImplicitParams({@ApiImplicitParam(name = "poolId", value = "游泳池id", dataType = "Integer", required = false),
            @ApiImplicitParam(name = "poolName", value = "泳池名称", dataType = "String", required = false),
            @ApiImplicitParam(name = "pageNum", value = "当前页index", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页面数据条数", dataType = "Integer", required = true)
    })
    public ApiResponse getAllPools(@RequestParam(value = "poolId", required = false) Integer poolId,
                                   @RequestParam(value = "poolName", required = false) String poolName,
                                   @RequestParam(value = "pageNum", required = true) Integer pageNum,
                                   @RequestParam(value = "pageSize", required = true) Integer pageSize) {
        SwimmingPool pool = new SwimmingPool();
        pool.setPoolId(poolId);
        pool.setPoolName(poolName);
        pool.setPageNum(pageNum);
        pool.setPageSize(pageSize);
        return swimmingPoolService.getAllPools(pool);
    }

}
